import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Title: helloServlet
 * @Author 郑雨杭
 * @Package PACKAGE_NAME
 * @Date 2024/7/27 22:23
 * @description:
 */
@WebServlet("/hello")
public class helloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession(false);
        if(session==null){
            resp.sendRedirect(req.getContextPath()+"/login.html");
            return;
        }
        String username = (String) session.getAttribute("username");
        String loginTime = (String) session.getAttribute("loginTime");
        resp.setContentType("text/html; charset=UTF-8");
        resp.getWriter().write("<h1>你好，"+username+"</h1>"+"</br><h1>上次登录时间是："+loginTime+"</h1>");
    }
}
